home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / QDDVX102.ZIP / contrib / dvx / inc / x11 / region.h < prev    next >
Text File  |  1993-07-15  |  5KB  |  165 lines

  1. /* $XConsortium: region.h,v 11.11 89/11/14 18:12:08 rws Exp $ */
  2. /************************************************************************
  3. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  4. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  5.  
  6.                         All Rights Reserved
  7.  
  8. Permission to use, copy, modify, and distribute this software and its 
  9. documentation for any purpose and without fee is hereby granted, 
  10. provided that the above copyright notice appear in all copies and that
  11. both that copyright notice and this permission notice appear in 
  12. supporting documentation, and that the names of Digital or MIT not be
  13. used in advertising or publicity pertaining to distribution of the
  14. software without specific, written prior permission.  
  15.  
  16. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  17. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  18. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  19. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  20. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  21. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  22. SOFTWARE.
  23.  
  24. ************************************************************************/
  25.  
  26. #include <X11/Xlibint.h> /* Was "Xlibint.h" POHC 90/12/17 */
  27.  
  28. typedef struct _Box { /* Tagged. POHC 90/10/08 */
  29.     short x1, x2, y1, y2;
  30. } Box, BOX, BoxRec, *BoxPtr;
  31.  
  32. typedef struct _RECTANGLE { /* Tagged. POHC 90/10/08 */
  33.     short x, y, width, height;
  34. }RECTANGLE, RectangleRec, *RectanglePtr;
  35.  
  36. #define TRUE 1
  37. #define FALSE 0
  38. #define MAXSHORT 32767
  39. #define MINSHORT -MAXSHORT
  40. #ifndef MAX
  41. #define MAX(a,b) (((a) > (b)) ? (a) : (b))
  42. #endif
  43. #ifndef MIN
  44. #define MIN(a,b) (((a) < (b)) ? (a) : (b))
  45. #endif
  46.  
  47.  
  48. /* 
  49.  *   clip region
  50.  */
  51.  
  52. typedef struct _XRegion {
  53.     long size;
  54.     long numRects;
  55.     BOX *rects;
  56.     BOX extents;
  57. } REGION;
  58.  
  59. /* Xutil.h contains the declaration: 
  60.  * typedef struct _XRegion *Region; 
  61.  */   
  62.  
  63. /*  1 if two BOXs overlap.
  64.  *  0 if two BOXs do not overlap.
  65.  *  Remember, x2 and y2 are not in the region 
  66.  */
  67. #define EXTENTCHECK(r1, r2) \
  68.     ((r1)->x2 > (r2)->x1 && \
  69.      (r1)->x1 < (r2)->x2 && \
  70.      (r1)->y2 > (r2)->y1 && \
  71.      (r1)->y1 < (r2)->y2)
  72.  
  73. /*
  74.  *  update region extents
  75.  */
  76. #define EXTENTS(r,idRect){\
  77.             if((r)->x1 < (idRect)->extents.x1)\
  78.               (idRect)->extents.x1 = (r)->x1;\
  79.             if((r)->y1 < (idRect)->extents.y1)\
  80.               (idRect)->extents.y1 = (r)->y1;\
  81.             if((r)->x2 > (idRect)->extents.x2)\
  82.               (idRect)->extents.x2 = (r)->x2;\
  83.             if((r)->y2 > (idRect)->extents.y2)\
  84.               (idRect)->extents.y2 = (r)->y2;\
  85.         }
  86.  
  87. /*
  88.  *   Check to see if there is enough memory in the present region.
  89.  */
  90. #define MEMCHECK(reg, rect, firstrect){\
  91.         if ((reg)->numRects >= ((reg)->size - 1)){\
  92.           (firstrect) = (BOX *) Xrealloc \
  93.           ((char *)(firstrect), (unsigned) (2 * (sizeof(BOX)) * ((reg)->size)));\
  94.           if ((firstrect) == 0)\
  95.             return(0);\
  96.           (reg)->size *= 2;\
  97.           (rect) = &(firstrect)[(reg)->numRects];\
  98.          }\
  99.        }
  100.  
  101. /*  this routine checks to see if the previous rectangle is the same
  102.  *  or subsumes the new rectangle to add.
  103.  */
  104.  
  105. #define CHECK_PREVIOUS(Reg, R, Rx1, Ry1, Rx2, Ry2)\
  106.                (!(((Reg)->numRects > 0)&&\
  107.                   ((R-1)->y1 == (Ry1)) &&\
  108.                   ((R-1)->y2 == (Ry2)) &&\
  109.                   ((R-1)->x1 <= (Rx1)) &&\
  110.                   ((R-1)->x2 >= (Rx2))))
  111.  
  112. /*  add a rectangle to the given Region */
  113. #define ADDRECT(reg, r, rx1, ry1, rx2, ry2){\
  114.     if (((rx1) < (rx2)) && ((ry1) < (ry2)) &&\
  115.         CHECK_PREVIOUS((reg), (r), (rx1), (ry1), (rx2), (ry2))){\
  116.               (r)->x1 = (rx1);\
  117.               (r)->y1 = (ry1);\
  118.               (r)->x2 = (rx2);\
  119.               (r)->y2 = (ry2);\
  120.               EXTENTS((r), (reg));\
  121.               (reg)->numRects++;\
  122.               (r)++;\
  123.             }\
  124.         }
  125.  
  126.  
  127.  
  128. /*  add a rectangle to the given Region */
  129. #define ADDRECTNOX(reg, r, rx1, ry1, rx2, ry2){\
  130.             if ((rx1 < rx2) && (ry1 < ry2) &&\
  131.                 CHECK_PREVIOUS((reg), (r), (rx1), (ry1), (rx2), (ry2))){\
  132.               (r)->x1 = (rx1);\
  133.               (r)->y1 = (ry1);\
  134.               (r)->x2 = (rx2);\
  135.               (r)->y2 = (ry2);\
  136.               (reg)->numRects++;\
  137.               (r)++;\
  138.             }\
  139.         }
  140.  
  141. #define EMPTY_REGION(pReg) pReg->numRects = 0
  142.  
  143. #define REGION_NOT_EMPTY(pReg) pReg->numRects
  144.  
  145. #define INBOX(r, x, y) \
  146.       ( ( ((r).x2 >= x)) && \
  147.         ( ((r).x1 <= x)) && \
  148.         ( ((r).y2 >= y)) && \
  149.         ( ((r).y1 <= y)) )
  150.  
  151. /*
  152.  * number of points to buffer before sending them off
  153.  * to scanlines() :  Must be an even number
  154.  */
  155. #define NUMPTSTOBUFFER 200
  156.  
  157. /*
  158.  * used to allocate buffers for points and link
  159.  * the buffers together
  160.  */
  161. typedef struct _POINTBLOCK {
  162.     XPoint pts[NUMPTSTOBUFFER];
  163.     struct _POINTBLOCK *next;
  164. } POINTBLOCK;
  165.